import 'dart:ui';

import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_lifecycle_base/base_state_widget.dart';
import 'package:provider/provider.dart';
import 'package:route_manager/app_config.dart';
import 'package:route_manager/route_bridge.dart';
import 'package:wallet_home/module_config.dart';
import 'package:wallet_home/page/qrcode/qrcode_generate.dart';
import 'package:wallet_home/page/theme/theme_provider.dart';
import 'package:wallet_home/tools/theme_utils.dart';
import 'package:wallet_home/widget/coins_manager.dart';

import 'module_wallet_home.dart';
import 'page/main_page/wallet_home_page.dart';
import 'module_config.dart';
import 'page/coin_manager/custom_amount.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
//  runApp(MyApp());
  await SpUtil.getInstance();
  String initRoute = window.defaultRouteName;
  if (initRoute.isNotEmpty) {
    ModuleConfig.moduleName = null;
  }

  runApp(MultiProvider(providers: [
    ChangeNotifierProvider.value(value: ThemeProvider()),
  ], child: MyApp()));

  ///状态栏全局透明
  SystemUiOverlayStyle systemUiOverlayStyle =
      SystemUiOverlayStyle(statusBarColor: Colors.transparent);
  SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}

class MyApp extends StatefulWidget {
  // This widget is the root of your application.
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    AppRouter.addModuleRoutes([ModuleWalletHome()]);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Consumer<ThemeProvider>(builder: (_, provider, __) {
      return MaterialApp(
        title: 'Flutter Demo',
//        theme: ThemeData(
//          // primarySwatch: Colors.blue,
//            primaryColor: MaterialColor(0xFF000000, <int, Color>{
//              500: Color(0xFF000000),
//            })),
//         home: MainBottomTabView(),
        home: CustomAmountPage(),
        // home: QRCodeScan(),
        // home: QRCodeGeneratePage(),
        navigatorKey: AppConfig.navigatorKey,

        onGenerateRoute: AppRouter.onGenerateRoute,
        theme: provider.getTheme(),
        themeMode: provider.getThemeMode(),
        darkTheme: provider.getTheme(isDarkMode: true),
        navigatorObservers: [BaseNavigationObserver()],
        // home: BiMoneyStartPage(),
      );
    });
  }
}
